using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using System.Text;

namespace Data_Access_Tier
{
	public class SYS_LOGData : DatabaseObjectBase
	{
		public SYS_LOGData()
		{
			Initialize(true);
		}
		public SYS_LOGData(Boolean newConnection)
		{
			Initialize(newConnection);
		}

		public Int32 SYS_LOG_Insert(Int64 SYS_ID, String MChine, String AccountWin, String UserID, String UserName, DateTime Created, String Module, Int32 Action, String Action_Name, String Reference, String IPLan, String IPWan, String Mac, String DeviceName, String Description, Boolean Active)
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.InsertCommand = new SqlCommand("SYS_LOG_Insert");
				_dbadapter.InsertCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.InsertCommand.Connection = _dbconn;
				_trans = _dbconn.BeginTransaction();
				_dbadapter.InsertCommand.Transaction = _trans;
				_dbadapter.InsertCommand.Parameters.Clear();
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@SYS_ID", SqlDbType.BigInt));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@MChine", SqlDbType.NVarChar, 200));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@AccountWin", SqlDbType.NVarChar, 50));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@UserID", SqlDbType.VarChar, 20));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@UserName", SqlDbType.NVarChar, 100));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@Created", SqlDbType.DateTime));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@Module", SqlDbType.NVarChar, 200));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@Action", SqlDbType.Int));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@Action_Name", SqlDbType.NVarChar, 50));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@Reference", SqlDbType.VarChar, 20));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@IPLan", SqlDbType.VarChar, 20));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@IPWan", SqlDbType.VarChar, 30));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@Mac", SqlDbType.VarChar, 40));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@DeviceName", SqlDbType.NVarChar, -1));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@Description", SqlDbType.NVarChar, 255));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@Active", SqlDbType.Bit));
				_dbadapter.InsertCommand.Prepare();
				SqlInt64 SYS_IDSQL = SYS_ID;
				_dbadapter.InsertCommand.Parameters["@SYS_ID"].Value = SYS_IDSQL;
				SqlString MChineSQL = MChine;
				_dbadapter.InsertCommand.Parameters["@MChine"].Value = MChineSQL;
				SqlString AccountWinSQL = AccountWin;
				_dbadapter.InsertCommand.Parameters["@AccountWin"].Value = AccountWinSQL;
				SqlString UserIDSQL = UserID;
				_dbadapter.InsertCommand.Parameters["@UserID"].Value = UserIDSQL;
				SqlString UserNameSQL = UserName;
				_dbadapter.InsertCommand.Parameters["@UserName"].Value = UserNameSQL;
				SqlDateTime CreatedSQL = SqlDateTime.Null;
				if (Created > DateTime.MinValue)
				{
					try
					{
						CreatedSQL = Created;
					}
					catch (Exception eCreated)
					{
						String CreatedMessage = eCreated.Message;
						CreatedSQL = SqlDateTime.Null;
					}
				}
				_dbadapter.InsertCommand.Parameters["@Created"].Value = CreatedSQL;
				SqlString ModuleSQL = Module;
				_dbadapter.InsertCommand.Parameters["@Module"].Value = ModuleSQL;
				SqlInt32 ActionSQL = Action;
				_dbadapter.InsertCommand.Parameters["@Action"].Value = ActionSQL;
				SqlString Action_NameSQL = Action_Name;
				_dbadapter.InsertCommand.Parameters["@Action_Name"].Value = Action_NameSQL;
				SqlString ReferenceSQL = Reference;
				_dbadapter.InsertCommand.Parameters["@Reference"].Value = ReferenceSQL;
				SqlString IPLanSQL = IPLan;
				_dbadapter.InsertCommand.Parameters["@IPLan"].Value = IPLanSQL;
				SqlString IPWanSQL = IPWan;
				_dbadapter.InsertCommand.Parameters["@IPWan"].Value = IPWanSQL;
				SqlString MacSQL = Mac;
				_dbadapter.InsertCommand.Parameters["@Mac"].Value = MacSQL;
				SqlString DeviceNameSQL = DeviceName;
				_dbadapter.InsertCommand.Parameters["@DeviceName"].Value = DeviceNameSQL;
				SqlString DescriptionSQL = Description;
				_dbadapter.InsertCommand.Parameters["@Description"].Value = DescriptionSQL;
				SqlBoolean ActiveSQL = Active;
				_dbadapter.InsertCommand.Parameters["@Active"].Value = ActiveSQL;
				Int32 returnvalue = Convert.ToInt32(_dbadapter.InsertCommand.ExecuteScalar());

				_trans.Commit();
				return returnvalue;
			}
			catch (SqlException e)
			{
				try
				{
					_trans.Rollback();
				}
				catch (SqlException ex)
				{
					throw new Exception("SQL Rollback Error: SYS_LOG_Insert: " + ex.Message, ex);
				}
				throw new Exception("SQL Error: SYS_LOG_Insert: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.InsertCommand != null)
					_dbadapter.InsertCommand.Dispose();
				CloseConnection();
			}
		}
		public Int32 SYS_LOG_Update(Int64 SYS_ID, String MChine, String AccountWin, String UserID, String UserName, DateTime Created, String Module, Int32 Action, String Action_Name, String Reference, String IPLan, String IPWan, String Mac, String DeviceName, String Description, Boolean Active)
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.UpdateCommand = new SqlCommand("SYS_LOG_Update");
				_dbadapter.UpdateCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.UpdateCommand.Connection = _dbconn;

				_trans = _dbconn.BeginTransaction();
				_dbadapter.UpdateCommand.Transaction = _trans;

				_dbadapter.UpdateCommand.Parameters.Clear();
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@SYS_ID", SqlDbType.BigInt));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@MChine", SqlDbType.NVarChar, 200));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@AccountWin", SqlDbType.NVarChar, 50));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@UserID", SqlDbType.VarChar, 20));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@UserName", SqlDbType.NVarChar, 100));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Created", SqlDbType.DateTime));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Module", SqlDbType.NVarChar, 200));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Action", SqlDbType.Int));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Action_Name", SqlDbType.NVarChar, 50));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Reference", SqlDbType.VarChar, 20));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@IPLan", SqlDbType.VarChar, 20));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@IPWan", SqlDbType.VarChar, 30));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Mac", SqlDbType.VarChar, 40));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@DeviceName", SqlDbType.NVarChar, -1));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Description", SqlDbType.NVarChar, 255));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Active", SqlDbType.Bit));
				_dbadapter.UpdateCommand.Prepare();
				SqlInt64 SYS_IDSQL = SYS_ID;
				_dbadapter.UpdateCommand.Parameters["@SYS_ID"].Value = SYS_IDSQL;
				SqlString MChineSQL = MChine;
				_dbadapter.UpdateCommand.Parameters["@MChine"].Value = MChineSQL;
				SqlString AccountWinSQL = AccountWin;
				_dbadapter.UpdateCommand.Parameters["@AccountWin"].Value = AccountWinSQL;
				SqlString UserIDSQL = UserID;
				_dbadapter.UpdateCommand.Parameters["@UserID"].Value = UserIDSQL;
				SqlString UserNameSQL = UserName;
				_dbadapter.UpdateCommand.Parameters["@UserName"].Value = UserNameSQL;
				SqlDateTime CreatedSQL = SqlDateTime.Null;
				if (Created > DateTime.MinValue)
				{
					try
					{
						CreatedSQL = Created;
					}
					catch (Exception eCreated)
					{
						String CreatedMessage = eCreated.Message;
						CreatedSQL = SqlDateTime.Null;
					}
				}
				_dbadapter.UpdateCommand.Parameters["@Created"].Value = CreatedSQL;
				SqlString ModuleSQL = Module;
				_dbadapter.UpdateCommand.Parameters["@Module"].Value = ModuleSQL;
				SqlInt32 ActionSQL = Action;
				_dbadapter.UpdateCommand.Parameters["@Action"].Value = ActionSQL;
				SqlString Action_NameSQL = Action_Name;
				_dbadapter.UpdateCommand.Parameters["@Action_Name"].Value = Action_NameSQL;
				SqlString ReferenceSQL = Reference;
				_dbadapter.UpdateCommand.Parameters["@Reference"].Value = ReferenceSQL;
				SqlString IPLanSQL = IPLan;
				_dbadapter.UpdateCommand.Parameters["@IPLan"].Value = IPLanSQL;
				SqlString IPWanSQL = IPWan;
				_dbadapter.UpdateCommand.Parameters["@IPWan"].Value = IPWanSQL;
				SqlString MacSQL = Mac;
				_dbadapter.UpdateCommand.Parameters["@Mac"].Value = MacSQL;
				SqlString DeviceNameSQL = DeviceName;
				_dbadapter.UpdateCommand.Parameters["@DeviceName"].Value = DeviceNameSQL;
				SqlString DescriptionSQL = Description;
				_dbadapter.UpdateCommand.Parameters["@Description"].Value = DescriptionSQL;
				SqlBoolean ActiveSQL = Active;
				_dbadapter.UpdateCommand.Parameters["@Active"].Value = ActiveSQL;
				Int32 returnvalue = Convert.ToInt32(_dbadapter.UpdateCommand.ExecuteScalar());

				_trans.Commit();
				return returnvalue;
			}
			catch (SqlException e)
			{
				try
				{
					_trans.Rollback();
				}
				catch (SqlException ex)
				{
					throw new Exception("SQL Rollback Error: SYS_LOG_Update: " + ex.Message, ex);
				}
				throw new Exception("SQL Error: SYS_LOG_Update: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.UpdateCommand != null)
					_dbadapter.UpdateCommand.Dispose();
				CloseConnection();
			}
		}
		public Int32 SYS_LOG_Disable(Int64 SYS_ID, ref Boolean Enabled)
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.UpdateCommand = new SqlCommand("SYS_LOG_Disable");
				_dbadapter.UpdateCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.UpdateCommand.Connection = _dbconn;

				_trans = _dbconn.BeginTransaction();
				_dbadapter.UpdateCommand.Transaction = _trans;

				_dbadapter.UpdateCommand.Parameters.Clear();
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@SYS_ID", SqlDbType.BigInt));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@enabled", SqlDbType.Bit));
				_dbadapter.UpdateCommand.Prepare();
				SqlInt64 SYS_IDSQL = SYS_ID;
				_dbadapter.UpdateCommand.Parameters["@SYS_ID"].Value = SYS_IDSQL;
				_dbadapter.UpdateCommand.Parameters["@enabled"].Direction = ParameterDirection.Output;
				Int32 returnvalue = Convert.ToInt32(_dbadapter.UpdateCommand.ExecuteScalar());

				_trans.Commit();
				return returnvalue;
			}
			catch (SqlException e)
			{
				try
				{
					_trans.Rollback();
				}
				catch (SqlException ex)
				{
					throw new Exception("SQL Rollback Error: SYS_LOG_Disable: " + ex.Message, ex);
				}
				throw new Exception("SQL Error: SYS_LOG_Disable: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.UpdateCommand != null)
					_dbadapter.UpdateCommand.Dispose();
				CloseConnection();
			}
		}
		public Int32 SYS_LOG_Delete(Int64 SYS_ID)
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.DeleteCommand = new SqlCommand("SYS_LOG_Delete");
				_dbadapter.DeleteCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.DeleteCommand.Connection = _dbconn;

				_trans = _dbconn.BeginTransaction();
				_dbadapter.DeleteCommand.Transaction = _trans;

				_dbadapter.DeleteCommand.Parameters.Clear();
				_dbadapter.DeleteCommand.Parameters.Add(new SqlParameter("@SYS_ID", SqlDbType.BigInt));
				_dbadapter.DeleteCommand.Prepare();
				SqlInt64 SYS_IDSQL = SYS_ID;
				_dbadapter.DeleteCommand.Parameters["@SYS_ID"].Value = SYS_IDSQL;
				Int32 returnvalue = Convert.ToInt32(_dbadapter.DeleteCommand.ExecuteScalar());

				_trans.Commit();
				return returnvalue;
			}
			catch (SqlException e)
			{
				try
				{
					_trans.Rollback();
				}
				catch (SqlException ex)
				{
					throw new Exception("SQL Rollback Error: SYS_LOG_Delete: " + ex.Message, ex);
				}
				throw new Exception("SQL Error: SYS_LOG_Delete: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.DeleteCommand != null)
					_dbadapter.DeleteCommand.Dispose();
				CloseConnection();
			}
		}
		public Int32 SYS_LOG_Save(Int64 SYS_ID, String MChine, String AccountWin, String UserID, String UserName, DateTime Created, String Module, Int32 Action, String Action_Name, String Reference, String IPLan, String IPWan, String Mac, String DeviceName, String Description, Boolean Active)
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.UpdateCommand = new SqlCommand("SYS_LOG_Save");
				_dbadapter.UpdateCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.UpdateCommand.Connection = _dbconn;

				_trans = _dbconn.BeginTransaction();
				_dbadapter.UpdateCommand.Transaction = _trans;

				_dbadapter.UpdateCommand.Parameters.Clear();
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@SYS_ID", SqlDbType.BigInt));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@MChine", SqlDbType.NVarChar, 200));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@AccountWin", SqlDbType.NVarChar, 50));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@UserID", SqlDbType.VarChar, 20));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@UserName", SqlDbType.NVarChar, 100));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Created", SqlDbType.DateTime));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Module", SqlDbType.NVarChar, 200));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Action", SqlDbType.Int));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Action_Name", SqlDbType.NVarChar, 50));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Reference", SqlDbType.VarChar, 20));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@IPLan", SqlDbType.VarChar, 20));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@IPWan", SqlDbType.VarChar, 30));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Mac", SqlDbType.VarChar, 40));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@DeviceName", SqlDbType.NVarChar, -1));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Description", SqlDbType.NVarChar, 255));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Active", SqlDbType.Bit));
				_dbadapter.UpdateCommand.Prepare();
				SqlInt64 SYS_IDSQL = SYS_ID;
				_dbadapter.UpdateCommand.Parameters["@SYS_ID"].Value = SYS_IDSQL;
				SqlString MChineSQL = MChine;
				_dbadapter.UpdateCommand.Parameters["@MChine"].Value = MChineSQL;
				SqlString AccountWinSQL = AccountWin;
				_dbadapter.UpdateCommand.Parameters["@AccountWin"].Value = AccountWinSQL;
				SqlString UserIDSQL = UserID;
				_dbadapter.UpdateCommand.Parameters["@UserID"].Value = UserIDSQL;
				SqlString UserNameSQL = UserName;
				_dbadapter.UpdateCommand.Parameters["@UserName"].Value = UserNameSQL;
				SqlDateTime CreatedSQL = SqlDateTime.Null;
				if (Created > DateTime.MinValue)
				{
					try
					{
						CreatedSQL = Created;
					}
					catch (Exception eCreated)
					{
						String CreatedMessage = eCreated.Message;
						CreatedSQL = SqlDateTime.Null;
					}
				}
				_dbadapter.UpdateCommand.Parameters["@Created"].Value = CreatedSQL;
				SqlString ModuleSQL = Module;
				_dbadapter.UpdateCommand.Parameters["@Module"].Value = ModuleSQL;
				SqlInt32 ActionSQL = Action;
				_dbadapter.UpdateCommand.Parameters["@Action"].Value = ActionSQL;
				SqlString Action_NameSQL = Action_Name;
				_dbadapter.UpdateCommand.Parameters["@Action_Name"].Value = Action_NameSQL;
				SqlString ReferenceSQL = Reference;
				_dbadapter.UpdateCommand.Parameters["@Reference"].Value = ReferenceSQL;
				SqlString IPLanSQL = IPLan;
				_dbadapter.UpdateCommand.Parameters["@IPLan"].Value = IPLanSQL;
				SqlString IPWanSQL = IPWan;
				_dbadapter.UpdateCommand.Parameters["@IPWan"].Value = IPWanSQL;
				SqlString MacSQL = Mac;
				_dbadapter.UpdateCommand.Parameters["@Mac"].Value = MacSQL;
				SqlString DeviceNameSQL = DeviceName;
				_dbadapter.UpdateCommand.Parameters["@DeviceName"].Value = DeviceNameSQL;
				SqlString DescriptionSQL = Description;
				_dbadapter.UpdateCommand.Parameters["@Description"].Value = DescriptionSQL;
				SqlBoolean ActiveSQL = Active;
				_dbadapter.UpdateCommand.Parameters["@Active"].Value = ActiveSQL;
				Int32 returnvalue = Convert.ToInt32(_dbadapter.UpdateCommand.ExecuteScalar());

				_trans.Commit();
				return returnvalue;
			}
			catch (SqlException e)
			{
				try
				{
					_trans.Rollback();
				}
				catch (SqlException ex)
				{
					throw new Exception("SQL Rollback Error: SYS_LOG_Save: " + ex.Message, ex);
				}
				throw new Exception("SQL Error: SYS_LOG_Save: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.UpdateCommand != null)
					_dbadapter.UpdateCommand.Dispose();
				CloseConnection();
			}
		}
		public DataSet SYS_LOG_GetList()
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.SelectCommand = new SqlCommand("SYS_LOG_GetList");
				_dbadapter.SelectCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.SelectCommand.Connection = _dbconn;
				_dbadapter.SelectCommand.Parameters.Clear();
				_dbadapter.SelectCommand.Prepare();
				_dbadapter.Fill(_data);

				return _data;
			}
			catch (SqlException e)
			{
				throw new Exception("SQL Error: SYS_LOG_GetList: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.SelectCommand != null)
					_dbadapter.SelectCommand.Dispose();
				CloseConnection();
			}
		}
		public DataSet SYS_LOG_Get(Int64 SYS_ID)
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.SelectCommand = new SqlCommand("SYS_LOG_Get");
				_dbadapter.SelectCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.SelectCommand.Connection = _dbconn;
				_dbadapter.SelectCommand.Parameters.Clear();
				_dbadapter.SelectCommand.Parameters.Add(new SqlParameter("@SYS_ID", SqlDbType.BigInt));
				_dbadapter.SelectCommand.Prepare();
				SqlInt64 SYS_IDSQL = SYS_ID;
				_dbadapter.SelectCommand.Parameters["@SYS_ID"].Value = SYS_IDSQL;
				_dbadapter.Fill(_data);

				return _data;
			}
			catch (SqlException e)
			{
				throw new Exception("SQL Error: SYS_LOG_Get: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.SelectCommand != null)
					_dbadapter.SelectCommand.Dispose();
				CloseConnection();
			}
		}
	}
}
